package dao

import (
	"context"
	"quipus/internal/database/model"

	apb "quipus/proto/gen/assist"
)

type DBOperator interface {
	// User model related methods.
	CreateUser(ctx context.Context, create *model.User) error
	UpdateUser(ctx context.Context, update *apb.UpdateUser) (*model.User, error)
	ListUsers(ctx context.Context, find *apb.FindUser) ([]*model.User, int64, error)
	GetUser(ctx context.Context, find *apb.FindUser) (*model.User, error)
	DeleteUser(ctx context.Context, delete *apb.DeleteUser) error
	ListUserSettings(ctx context.Context, userId int32) ([]*model.UserSetting, error)
	GetUserSetting(ctx context.Context, userId int32, key string) (*model.UserSetting, error)
	UpsertUserSetting(ctx context.Context, update *model.UserSetting) error
	GetUserAccessTokens(ctx context.Context, userId int32) ([]*apb.AccessTokensUserSetting_AccessToken, error)

	// Knot model related methods.
	CreateKnot(ctx context.Context, create *model.Knot) error
	UpdateKnot(ctx context.Context, update *apb.UpdateKnot) error
	DeleteKnot(ctx context.Context, delete *apb.DeleteKnot) error

	CreateKnotRT(ctx context.Context, create *model.KnotRecommendTopic) error
	DeleteKnotRT(ctx context.Context, knotId int32) error
	GetKnotRT(ctx context.Context, knotId int32) (*model.KnotRecommendTopic, error)

	ListKnots(ctx context.Context, find *apb.FindKnot) ([]*model.Knot, int32, error)
	CreateTopic(ctx context.Context, create *model.Topic) error
	CreateTopicInBatchs(ctx context.Context, create []*model.Topic) error
	ListTopics(ctx context.Context, find *apb.FindTopic) ([]*model.Topic, int32, error)
	DeleteTopic(ctx context.Context, delete *apb.DeleteTopic) error
	GetTopic(ctx context.Context, id int32) (*model.Topic, error)
	GetTopicUnits(ctx context.Context, id int32) ([]*model.Topic, error)

	CreateSubject(ctx context.Context, create *model.Subject) error
	DeleteSubject(ctx context.Context, id int32) error
	ListSubjects(ctx context.Context, find *apb.FindSubject) ([]*model.Subject, int32, error)
	ListFavorSubjects(ctx context.Context, find *apb.FindSubject) ([]*model.Subject, int32, error)
	GetSubject(ctx context.Context, subject string) (*model.Subject, error)
	UpdateSubject(ctx context.Context, subject *model.Subject) (*model.Subject, error)

	GetSubjectById(ctx context.Context, subjectId int32) (*model.Subject, error)
	FavorSubject(ctx context.Context, userId int32, subjectId int32) (*model.Subject, error)
	UnFavorSubject(ctx context.Context, userId int32, subjectId int32) (*model.Subject, error)
	CountSubjectFavors(ctx context.Context, subjectId int32) (int32, error)
	CheckFavorSubject(ctx context.Context, userId int32, subjectId int32) (bool, error)

	GetKnot(ctx context.Context, find *apb.FindKnot) (*model.Knot, error)

	CreateWorkflow(ctx context.Context, create *model.Workflow) error
	DeleteWorkflow(ctx context.Context, id int32) error
	ListWorkflows(ctx context.Context, find *apb.FindWorkflow) ([]*model.Workflow, int32, error)
	GetWorkflow(ctx context.Context, find *apb.FindWorkflow) (*model.Workflow, error)

	CreateWorkflowRelation(ctx context.Context, create *model.WorkflowRelation) error
	ListWorkflowRelation(ctx context.Context, find *apb.WorkflowRelation) ([]*model.WorkflowRelation, error)

	DeleteWorkflowRelaton(ctx context.Context, delete *apb.WorkflowRelation) error

	// UpdateKnot(ctx context.Context, update *models.UpdateKnot) error
	// DeleteKnot(ctx context.Context, delete *models.DeleteKnot) error

	UpsertKnotRelation(ctx context.Context, upsert *model.KnotRelation) error
	ListKnotRelations(ctx context.Context, find *apb.FindKnotRelation) ([]*model.KnotRelation, error)
	DeleteKnotRelation(ctx context.Context, delete *model.KnotRelation) error
	// DeleteKnotRelation(ctx context.Context, delete *model.KnotRelation) error

	// Resource model related methods.
	CreateResource(ctx context.Context, create *model.Resource) error
	GetResource(ctx context.Context, find *apb.FindResource) (*model.Resource, error)
	ListResources(ctx context.Context, find *apb.FindResource) ([]*model.Resource, int64, error)
	UpdateResource(ctx context.Context, update *apb.UpdateResource) error
	DeleteResource(ctx context.Context, delete *apb.DeleteResource) error

	// Reaction model related methods.
	UpsertReaction(ctx context.Context, create *model.Reaction) error
	ListReactions(ctx context.Context, find *apb.FindReaction) ([]*model.Reaction, error)
	DeleteReaction(ctx context.Context, delete *apb.DeleteReaction) error

	CreateActivity(ctx context.Context, create *model.Activity) error
	// ListActivities(ctx context.Context, find *FindActivity) ([]*Activity, error)

	// Inbox model related methods.
	CreateInbox(ctx context.Context, create *model.Inbox) error
	// ListInboxes(ctx context.Context, find *FindInbox) ([]*Inbox, error)
	// UpdateInbox(ctx context.Context, update *UpdateInbox) (*Inbox, error)
	// DeleteInbox(ctx context.Context, delete *DeleteInbox) error

	UpsertKnotArrangement(ctx context.Context, upsert *model.KnotArrangement) error
	ListKnotArrangement(ctx context.Context, find *apb.KnotArrangement) ([]*model.KnotArrangement, error)

	UpsertSystemSetting(ctx context.Context, upsert *model.SystemSetting) error
	ListSystemSettings(ctx context.Context, settingKey string) ([]*model.SystemSetting, error)
	DeleteSystemSettings(ctx context.Context, settingKey string) error

	// DeleteWorkspaceSetting(ctx context.Context, delete *DeleteWorkspaceSetting) error

	CreateWebhook(ctx context.Context, create *model.Webhook) error
	ListWebhooks(ctx context.Context, find *apb.FindWebhook) ([]*model.Webhook, error)
	GetWebhook(ctx context.Context, find *apb.FindWebhook) (*model.Webhook, error)
	UpdateWebhook(ctx context.Context, update *apb.UpdateWebhook) (*model.Webhook, error)
	DeleteWebhook(ctx context.Context, delete *apb.DeleteWebhook) error

	GetIdentityProviderById(ctx context.Context, id int32) (*model.Idp, error)
	GetIdentityProviderByType(ctx context.Context, idpType string, tenantId int32) (*model.Idp, error)
	CreateIdentityProvider(ctx context.Context, create *model.Idp) error
	ListIdentityProviders(ctx context.Context, find *apb.FindIdentityProvider) ([]*model.Idp, error)
	UpdateIdentityProvider(ctx context.Context, update *apb.UpdateIdentityProvider) (*model.Idp, error)
	DeleteIdentityProvider(ctx context.Context, id int32) error

	ListUserFavorAssistant(ctx context.Context, userId int32) ([]*model.FavorAssistant, error)

	CreateLLMAssistant(ctx context.Context, create *model.LlmAssistant) error
	DeleteLLMAssistant(ctx context.Context, assistantId int32) error
	UpdateLLMAssistant(ctx context.Context, update *apb.UpdateLLMAssistant) (*model.LlmAssistant, error)
	GetLLMAssistant(ctx context.Context, assistantId int32) (*model.LlmAssistant, error)
	ListLLMAssistants(ctx context.Context, find *apb.FindLLMAssistant) ([]*model.LlmAssistant, int32, error)

	CreateLLMProvider(ctx context.Context, create *model.LlmProvider) error
	DeleteLLMProvider(ctx context.Context, providerId int32) error
	GetLLMProvider(ctx context.Context, providerId int32) (*model.LlmProvider, error)
	UpdateLLMProvider(ctx context.Context, update *apb.UpdateLLMProvider) (*model.LlmProvider, error)
	ListLLMProviders(ctx context.Context, find *apb.FindLLMProvider) ([]*model.LlmProvider, int32, error)

	CreateLLMModel(ctx context.Context, create *model.LlmModel) error
	DeleteLLMModel(ctx context.Context, modelId int32) error
	GetLLMModel(ctx context.Context, modelId int32) (*model.LlmModel, error)
	UpdateLLMModel(ctx context.Context, update *apb.UpdateLLMModel) (*model.LlmModel, error)
	ListLLMModels(ctx context.Context, find *apb.FindLLMModel) ([]*model.LlmModel, int32, error)

	// GetModelProvider(ctx context.Context, assistantId int32) (*model.LlmProvider, error)
	// GetModelProvider(ctx context.Context, modelId int32) (*model.LlmProvider, error)User

	CreateTenant(ctx context.Context, create *model.Tenant) error
	UpdateTenant(ctx context.Context, update *apb.UpdateTenant) (*model.Tenant, error)
	ListTenants(ctx context.Context, find *apb.FindTenant) ([]*model.Tenant, int64, error)
	GetTenant(ctx context.Context, find *apb.FindTenant) (*model.Tenant, error)
	DeleteTenant(ctx context.Context, delete *apb.DeleteTenant) error

	CreateGranary(ctx context.Context, create *model.Granary) error
	DeleteGranary(ctx context.Context, granayId int32) error
	GetGranary(ctx context.Context, granayId int32) (*model.Granary, error)
	UpdateGranary(ctx context.Context, update *apb.UpdateGranary) (*model.Granary, error)
	UpdateGranarySimple(ctx context.Context, update *model.Granary) error
	ListGranaries(ctx context.Context, find *apb.FindGranary) ([]*model.Granary, int32, error)
	UpsertGranaryResource(ctx context.Context, upsert *model.GranaryResource) error
	StopGranaryResource(ctx context.Context, find *apb.FindGranaryResource) error
	DeleteGranaryResource(ctx context.Context, delete *apb.FindGranaryResource) error
	ListGranaryResources(ctx context.Context, find *apb.FindGranaryResource) ([]*model.GranaryResource, error)

	UpsertVirtUser(ctx context.Context, user *model.VirtUser) error
	GetVirtUser(ctx context.Context, userId int32) (*model.VirtUser, error)
	DeleteVirtUser(ctx context.Context, userId int32) error
	UpsertAttachUser(ctx context.Context, user *model.AttachUser) error
	GetAttachUser(ctx context.Context, userId int32) (*model.AttachUser, error)
	DeleteAttachUser(ctx context.Context, userId int32) error
}
